export const vaildatorRules = vm => {
  const rules = {
    warehouse_code: [
      {
        required: true,
        trigger: 'change',
        message: '请选择仓库',
      },
    ],
    inbound_order_type: [
      {
        required: true,
        trigger: 'change',
        message: '请选择入库类型',
      },
    ],
    container_type: [
      {
        required: true,
        trigger: 'change',
        message: '请选择货柜类型',
      },
    ],
    estimate_delivery_time: [
      {
        required: true,
        trigger: 'change',
        message: '请选择预计送达时间',
      },
    ],
    inbound_packages_list: [
      {
        required: true,
        trigger: 'change',
        message: '请输入打包箱列表',
      },
    ],
    shipping_method: [
      {
        required: true,
        trigger: 'change',
        message: '请输入运输方式',
      },
    ],

    validetaRuleHandler_04(rule, value, callback) {
      const oneIndex = Number(rule.fullField.split('.')[1]) // 获取settingList下标
      const arr = vm.infoModel.inbound_packages_list || []

      if (arr.length > 0) {
        for (let i = 0; i < arr.length; i++) {
          if (!arr[i].weight && oneIndex === i) {
            callback(new Error('请输入箱子重量'))
            break
          } else if (!arr[i].mass_unit && oneIndex === i) {
            callback(new Error('请选择重量单位'))
            break
          } else if (oneIndex === i) {
            callback()
            break
          }
        }
      } else {
        callback()
      }
    },

    validetaRuleHandler_03(rule, value, callback) {
      const oneIndex = Number(rule.fullField.split('.')[1]) // 获取settingList下标
      const arr = vm.infoModel.inbound_packages_list || []

      if (arr.length > 0) {
        for (let i = 0; i < arr.length; i++) {
          if (!arr[i].length && oneIndex === i) {
            callback(new Error('请输入箱子长度'))
            break
          } else if (!arr[i].width && oneIndex === i) {
            callback(new Error('请输入箱子宽度'))
            break
          } else if (!arr[i].height && oneIndex === i) {
            callback(new Error('请输入箱子高度'))
            break
          } else if (!arr[i].distance_unit && oneIndex === i) {
            callback(new Error('请选择尺寸单位'))
            break
          } else if (oneIndex === i) {
            callback()
            break
          }
        }
      } else {
        callback()
      }
    },

    /**
     * 规则验证
     */

    validetaDedRule(rule, value, callback) {
      const oneIndex = Number(rule.fullField.split('.')[1]) // 获取settingList下标
      const twoIndex = Number(rule.fullField.split('.')[3]) // 获取list下标

      const arr = vm.infoModel.inbound_packages_list[oneIndex].inbound_packages_items_list || []
      if (arr.length > 0) {
        for (let i = 0; i < arr.length; i++) {
          if (!arr[i][rule.key] && twoIndex === i) {
            // 循环到当前forItem 一定要break 不然会循环下去，影响验证
            callback(new Error(rule.msgName))
            break
          } else if (twoIndex === i) {
            callback()
            break
          }
        }
      } else {
        callback()
      }
    },

    validetaRuleHandler_05(rule, value, callback) {
      const oneIndex = Number(rule.fullField.split('.')[1]) // 获取settingList下标
      const arr = vm.infoModel.inbound_packages_list || []

      if (arr.length > 0) {
        for (let i = 0; i < arr.length; i++) {
          if (!arr[i].quantity && oneIndex === i) {
            callback(new Error('请输入箱子数量'))
            break
          } else if (oneIndex === i) {
            callback()
            break
          }
        }
      } else {
        callback()
      }
    },

    validetaRuleHandler_06(rule, value, callback) {
      const oneIndex = Number(rule.fullField.split('.')[1]) // 获取settingList下标
      const arr = vm.infoModel.inbound_packages_list || []

      if (arr.length > 0) {
        for (let i = 0; i < arr.length; i++) {
          if (!arr[i].box_model && oneIndex === i) {
            callback(new Error('请输入箱号'))
            break
          } else if (oneIndex === i) {
            callback()
            break
          }
        }
      } else {
        callback()
      }
    },
  }
  return rules
}
